home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9766 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  83 lines

  1. Path: earth.superlink.net!usenet
  2. From: Michael Rizzo <rizzom@mars.superlink.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Help:  error while linking:  unresolved external symbol
  5. Date: Mon, 04 Mar 1996 07:02:58 -0500
  6. Organization: SuperNet Inc. (908) 828-8988
  7. Message-ID: <313ADBF2.5FAB@mars.superlink.net>
  8. NNTP-Posting-Host: ez8.superlink.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. Hi,
  15.  
  16.     I am using MS Visual C++ 4.0 trying to create a console app.  
  17. The problem is:
  18.     I have template class:
  19.  
  20.     template <class T> class MemManager
  21.     {
  22.         T *mem[100];
  23.     public:
  24.         MemManager();
  25.         T Fetch(int);
  26.         Store(T, int);
  27.         ~MemManager() {delete [] *mem;};
  28.     };
  29.  
  30.     template <class T> MemManager<T>::MemManager()
  31.     {
  32.         for (int i=0;i<100;i++)
  33.             mem[i] = new T;
  34.     }
  35.  
  36.     template <class T> T MemManager<T>::Fetch(int ind)
  37.     {
  38.         return *mem[ind];
  39.     }
  40.  
  41.     template <class T> MemManager<T>::Store(T element, int ind)
  42.     {
  43.         *mem[ind] = element;
  44.     }
  45.  
  46. I then instantiate the template class in the following way:
  47. class VMProc
  48. {
  49.     stateType state;  //previously defined enum type
  50.     int PC, AC;
  51.     char IR[11];
  52.     MemManager<mstring> instMemMan;  //previously declared class
  53.     MemManager<int> dataMemMan;
  54.  
  55. public:
  56.     VMProc();
  57.     void DisplayMem();
  58.     boolean Initialize();
  59.     stateType GetState();
  60.     void DoInstruction();
  61. };
  62.  
  63. These class definitions are in the same .h file with the template class 
  64. being defined first.  The code for the member functions is also in the 
  65. same .cpp file.
  66.  
  67. Ant time I call the Store member function, I get LNK2001: unresolved 
  68. external symbol public: int __thiscall MemManager<class 
  69. mstring>::Store(class 
  70. mstring,int)"(?Store@?$MemManager@Vmstring@@@@QAEHVmstring@@H@Z) 
  71.  
  72. and the same thing for the class instantiated as <int>.
  73.  
  74. As I am relativly new to C++, this is driving me nuts! I have been 
  75. reading the help file that come with the compiler, but I just can't 
  76. figure this out.  (Mostly because I am not entirely sure what an 
  77. unresolved external symbol error means)
  78. Any help would be greatly appreciated.
  79. Thanks in advance
  80.  
  81. Mike Rizzo
  82. rizzom@mars.superlink.net
  83.